package com.flash.InventoryManagement.controller;

import com.flash.GlobalManagement.util.Dbutil;
import com.flash.GlobalManagement.util.TableIdUtil;
import com.flash.GlobalManagement.util.TableNameUtil;
import com.flash.GlobalManagement.util.TableTimeUtil;
import com.flash.InventoryManagement.entity.CashAccrualStock;
import com.flash.InventoryManagement.service.CashAccrualStockService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.SocketHandler;

/**
 * @author jr
 * @version 1.0
 * @date 2022/8/23
 */
@Controller
public class CashAccrualStockContrller {

    @Resource
    CashAccrualStockService cashAccrualStockService;

    @Resource
    Dbutil dbutil;

    @RequestMapping("selectCashAccrualStock")
    @ResponseBody
    public Map selectCashAccrualStock(CashAccrualStock cashAccrualStock,int page,int limit){
        System.out.println("11111"+cashAccrualStock);
        System.out.println("查询现金应收应付库存");
        Map map = new HashMap();
        //调用查询方法
        List cashAccrualStockList = cashAccrualStockService.selectCashAccrualStock(cashAccrualStock,page,limit);
        //记录总条数
        int count = cashAccrualStockService.countCashAccrualStock();
        //code
        map.put("code", 0);
        //msg
        map.put("msg", "");
        //count
        map.put("count", count);
        //data
        map.put("data", cashAccrualStockList);
        return map;
    }
    @RequestMapping("insertCashAccrualStock")
    @ResponseBody
    public String insertCashAccrualStock(CashAccrualStock cashAccrualStock){
        System.out.println("增加现金应收应付库存");
        //自动增长id
        cashAccrualStock.setCashAccrualStockId(dbutil.getMaxId3(TableIdUtil.CASID, TableNameUtil.CAS,TableTimeUtil.CASTime,cashAccrualStock.getDateAccrualStock()));
        //Servic调用增加方法
        int i = cashAccrualStockService.insertCashAccrualStock(cashAccrualStock);
        if (i>0){
            return "增加成功";
        }else {
            return "增加失败";
        }
    }

    @RequestMapping("updateCashAccrualStock")
    @ResponseBody
    public String updateCashAccrualStock(CashAccrualStock cashAccrualStock){
        System.out.println("修改现金应收应付库存");
        //Servic调用修改方法
        int i = cashAccrualStockService.updateCashAccrualStock(cashAccrualStock);
        if (i>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }

    @RequestMapping("deleteCashAccrualStock")
    @ResponseBody
    public String deleteCashAccrualStock(CashAccrualStock cashAccrualStock){
        System.out.println("删除现金应收应付库存");
        //调用删除方法
        int i = cashAccrualStockService.deleteCashAccrualStock(cashAccrualStock);
        if (i>0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

}
